package com.cade.agriculturemall.base;

import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by Lobby on 2017/11/24.
 */


public abstract class BaseAdapter<VH extends BaseViewHolder> extends RecyclerView.Adapter<VH> implements FWViewHolder.OnViewHolderClickListener {


    private OnItemClickListener mOnItemClickListener;

    private OnItemLongClickListener mOnItemLongClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    public void setOnItemLongClickListener(OnItemLongClickListener onItemLongClickListener) {
        mOnItemLongClickListener = onItemLongClickListener;
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {
        holder.setOnViewHolderClickListener(this);
        onBindViewHolderWrapper(holder, position);
    }

    public abstract void onBindViewHolderWrapper(VH holder, int position);

    @Override
    public void onItemClick(View view, int position) {
        if (mOnItemClickListener != null) {
            mOnItemClickListener.onItemClick(view, position);
        }
    }

    @Override
    public void onItemLongClick(View view, int position) {
        if (mOnItemLongClickListener != null) {
            mOnItemLongClickListener.onLongItemClick(view, position);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public interface OnItemLongClickListener {
        void onLongItemClick(View view, int position);
    }
}
